<?php
class Pengaturan_kelas extends CI_Model 
{

	function __construct()
	{
		parent::__construct();
	}

	function detail($id_mr_th_ajaran,$id_lembaga)
	{
		$this->db->select('id_atur_kelas, mr_th_ajaran.*, mr_kelas.*, mr_pegawai.id_mr_pegawai, nm_pegawai, nama_lembaga');
		$this->db->from('atur_kelas');
		$this->db->join('mr_lembaga', 'mr_lembaga.id_lembaga = atur_kelas.id_lembaga');
		$this->db->join('mr_th_ajaran', 'mr_th_ajaran.id_mr_th_ajaran = atur_kelas.id_mr_th_ajaran');
		$this->db->join('mr_kelas', 'mr_kelas.id_mr_kelas = atur_kelas.id_mr_kelas');
		$this->db->join('mr_pegawai', 'mr_pegawai.id_mr_pegawai = atur_kelas.id_mr_pegawai');
		$this->db->where('mr_th_ajaran.id_mr_th_ajaran', $id_mr_th_ajaran);
		$this->db->where('atur_kelas.id_lembaga', $id_lembaga);
		$this ->db->order_by('kelas');

		$query = $this->db->get();		
		return $query->result();
	}
	
	function kelas_th_ajar($id_mr_th_ajaran,$id_lembaga)
	{
		$this->db->select('*');
		$this->db->from('mr_kelas');
		$this->db->where('id_mr_kelas not in (select id_mr_kelas from atur_kelas where id_mr_th_ajaran ='.$id_mr_th_ajaran.' and id_lembaga = '.$id_lembaga.')');
		$this ->db->order_by('kelas');

		$query = $this->db->get();		
		return $query->result();
	}
	
	function add($dataInsert)
	{
		$query = $this->db->insert('atur_kelas', $dataInsert);
		return $query;
	}
	
	function delete($id_atur_kelas)
	{
		$this->db->where('id_atur_kelas', $id_atur_kelas);
		$delete = $this->db->delete('atur_kelas');
		return $delete;
	}
	
}